package com.me.brainlessbirds.actors.hud;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.me.brainlessbirds.Assets;
import com.me.brainlessbirds.actors.zombies.Zombie.ZombieType;
import com.me.brainlessbirds.actors.zombies.units.Brainless;
import com.me.brainlessbirds.screens.GameScreen;

public class ZombieSelector extends Actor
{
	protected TextureRegion	rgn	= new TextureRegion();

	public ZombieSelector(final Brainless zombie, float x, float y)
	{
		rgn = new TextureRegion(Assets.get().textureZombieSelection);

		setSize(128f, 64f);
		setOrigin(getWidth() / 2, getHeight() / 2);
		setPosition(x, y);
		setColor(getColor().r, getColor().g, getColor().b, getColor().a / 2f);

		this.addListener(new ClickListener()
		{
			@Override
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
			{
				// TODO : selection suivant la position x ? voir suivant sprite
				zombie.setSelected(false);
				if (x < getWidth() / 3)
				{
					zombie.changeType(ZombieType.SMOOTHIE);
				}
				else if (x > 2 * getWidth() / 3)
				{
					zombie.changeType(ZombieType.WINEHOUSE);
				}
				else
				{
					zombie.changeType(ZombieType.UNDERTAKER);
				}
				return false;
			}
		});

		GameScreen.get().getScene().addActor(this);
	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha)
	{
		batch.draw(rgn, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
	}
}
